const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    myCompanydata:'',
    userInfo:'',
    salarylistdata:[],
    isloading:true
  },
  goPge(e){
    let url = e.currentTarget.dataset["url"]
    let type=e.currentTarget.dataset.type
    if(url=='/pages/settlement/settlement'){
      Controller.checkAllowSettlement().then(res=>{
        console.log(res)
        if(res.code==0){
          wx.showModal({
            title: '提示',
            content: res.msg,
            showCancel:false,
            confirmColor:'#F08519',
            success (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }else{
          if(res.code==-3){
            wx.navigateTo({
              url:"/pages/userCompany/userCompany"
            });
          }else{
            wx.showModal({
              title: '提示',
              content: res.msg,
              showCancel:false,
              confirmColor:'#F08519',
              success (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }
        }
      }).catch(res=>{
        
      })
      return
    }
    if(url=='/pages/advance/advance'){
      Controller.checkAllowAdvancePay().then(res=>{
        if(res.code==0){
          wx.navigateTo({
              url:"/pages/advance/advance"
            });
        }else{
          if(res.code==-3){
            wx.navigateTo({
              url:"/pages/userCompany/userCompany"
            });
          }else{
            wx.showModal({
              title: '提示',
              content: res.msg,
              showCancel:false,
              confirmColor:'#F08519',
              success (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }
          
        }
      }).catch(res=>{
      })
      return
    }

    if(type=="switchTab"){
      wx.switchTab({ url:url});
    }else{
      wx.navigateTo({ url:url});
    }
    
  },
  onLoad: function (options) {
    this.myCompany()
    this.info()
  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          userInfo:res.data.baseData
        })
      }
    })
  },
  myCompany(){
    Controller.myCompany().then(res=>{
      if(res.data.baseData){
        this.setData({
          myCompanydata:res.data.baseData
        })
      }
      this.setData({
        isloading:false
      })
      this.salarylist()
    })
  },
  salarylist(){
    Controller.salarylist().then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          salarylistdata:res.data.baseData.list
        })
      }
   
    })
  },
  onShareAppMessage: function () {

  }
})